/*@Author: Maple
* @QQ:766158258
* @versioin: 1.0
* @LastEditTime: 2020-11-23 11:52:19
* @Description: toast免悬浮权限控制台,两秒会闪一次
*/
//"ui";

var Toastc = {}
var LogData = [];
Toastc.show = function () {
    importClass(android.widget.Toast);
    importClass(android.view.Gravity);
    importClass(android.graphics.Color);
    importPackage(android.content);
    setInterval(() => {
        var toast = Toast.makeText(context.getApplicationContext(), "toast", Toast.LENGTH_LONG);
        var view = ui.inflate(
            <vertical>
                <card cardBackgroundColor="#161824" cardCornerRadius="1" alpha="0.8" >
                    <text margin="10 6" text="Toast控制台:" textStyle="italic" textColor="#ffffff" textSize="14" layout_gravity="center|left" gravity="center|left"></text>
                </card >
                <View bg="#00000000" w="*" h="1" marginRight="1" marginLeft="1" />
                <vertical h="*" w="220" background="#000000" alpha="0.8">
                    <vertical h="260" w="*">
                        <list id="logList" padding="10 3 0 0" elevation="1dp" h="*" >
                            <linear>
                                <text size="13" text="{{time}} " textColor="#ffffff" />
                                <text size="13" text="{{message}}" textColor="#ffffff" />
                            </linear>
                        </list>
                    </vertical>
                </vertical >
            </vertical>
        )
        toast.setView(view);
        toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
        toast.show();
        view.logList.setDataSource(LogData)
        view.logList.scrollToPosition(LogData.length - 1)
        setTimeout(function () { toast.cancel(); }, 2000)
    }, 2000);
}
Toastc.log = function (str) {
    log(str.toString())
    LogData.push({ time: "[" + logDate() + "]", message: str.toString() })
}
// 测试输出
Toastc.show()
setInterval(function () {
    var smile = ["(ง •̀_•́)ง ", " ╮(๑•́ ₃•̀๑)╭", "ฅ’ω’ฅ ", "( ‘-ωก̀ )", "( ˘•灬•˘ )"]
    Toastc.log(smile[random(0, smile.length - 1)]);
}, 1000);


function logDate() {
    let date = new Date()
    let h = date.getHours();
    h = h < 10 ? ("0" + h) : h;
    let minute = date.getMinutes();
    minute = minute < 10 ? ('0' + minute) : minute;
    let second = date.getSeconds();
    second = second < 10 ? ('0' + second) : second;
    return h + ':' + minute + ':' + second;
}